/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MkDBPane.java
 *
 * Created on Aug 23, 2009, 11:25:44 AM
 */

package org.dbdir.client.gui;

import org.dbdir.Client;
import org.dbdir.core.helper.Database;

/**
 *
 * @author thotheolh
 */
public class MkDBPane extends javax.swing.JPanel {

    Client client;
    MainFrame frame;
    Database db;

    /** Creates new form MkDBPane */
    public MkDBPane(Client client, MainFrame frame) {
        initComponents();
        this.client = client;
        this.frame = frame;
        this.setSize(400,194);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        contentPane = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        aliasTF = new javax.swing.JTextField();
        pathTF = new javax.swing.JTextField();
        usrTF = new javax.swing.JTextField();
        pwdTF = new javax.swing.JTextField();
        bottomPane = new javax.swing.JPanel();
        leftPane = new javax.swing.JPanel();
        mainBtn = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        rightPane = new javax.swing.JPanel();
        mkDBBtn = new javax.swing.JButton();

        setLayout(new java.awt.BorderLayout());

        jLabel1.setText("DB Alias: ");

        jLabel2.setText("DB Path: ");

        jLabel3.setText("DB Username: ");

        jLabel4.setText("DB Password: ");

        aliasTF.setFont(new java.awt.Font("DejaVu Sans", 1, 13));
        aliasTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aliasTFActionPerformed(evt);
            }
        });

        pathTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pathTFActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout contentPaneLayout = new javax.swing.GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(contentPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(contentPaneLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(aliasTF, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(contentPaneLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pathTF, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, contentPaneLayout.createSequentialGroup()
                            .addComponent(jLabel4)
                            .addGap(18, 18, 18)
                            .addComponent(pwdTF))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, contentPaneLayout.createSequentialGroup()
                            .addComponent(jLabel3)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(usrTF, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(21, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(contentPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(aliasTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(pathTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(usrTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(pwdTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        add(contentPane, java.awt.BorderLayout.CENTER);

        bottomPane.setLayout(new java.awt.BorderLayout());

        leftPane.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        mainBtn.setText("Back to Main");
        mainBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mainBtnActionPerformed(evt);
            }
        });
        leftPane.add(mainBtn);

        jButton1.setText("DB");
        jButton1.setToolTipText("Manage DB page");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        leftPane.add(jButton1);

        bottomPane.add(leftPane, java.awt.BorderLayout.WEST);

        rightPane.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        mkDBBtn.setText("Make DB");
        mkDBBtn.setToolTipText("Update DB Profile properties");
        mkDBBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mkDBBtnActionPerformed(evt);
            }
        });
        rightPane.add(mkDBBtn);

        bottomPane.add(rightPane, java.awt.BorderLayout.EAST);

        add(bottomPane, java.awt.BorderLayout.SOUTH);
    }// </editor-fold>//GEN-END:initComponents

    private void aliasTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aliasTFActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_aliasTFActionPerformed

    private void mainBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mainBtnActionPerformed
        // TODO add your handling code here:
        frame.getActionPane();
}//GEN-LAST:event_mainBtnActionPerformed

    private void mkDBBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mkDBBtnActionPerformed
        // TODO add your handling code here:
        Database db = new Database(aliasTF.getText(),pathTF.getText(),usrTF.getText(),pwdTF.getText(),null);
        if(client.mkDBProfile(db)){
            frame.getManDBPane();
        }
}//GEN-LAST:event_mkDBBtnActionPerformed

    private void pathTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pathTFActionPerformed
        // TODO add your handling code here:

    }//GEN-LAST:event_pathTFActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        frame.getManDBPane();
}//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField aliasTF;
    private javax.swing.JPanel bottomPane;
    private javax.swing.JPanel contentPane;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel leftPane;
    private javax.swing.JButton mainBtn;
    private javax.swing.JButton mkDBBtn;
    private javax.swing.JTextField pathTF;
    private javax.swing.JTextField pwdTF;
    private javax.swing.JPanel rightPane;
    private javax.swing.JTextField usrTF;
    // End of variables declaration//GEN-END:variables

}
